package com.wangfugui.mybatisplus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wangfugui.mybatisplus.dao.TransactionDetailDao;
import com.wangfugui.mybatisplus.dao.UnrealizedPnlDao;
import com.wangfugui.mybatisplus.domain.TransactionDetail;
import com.wangfugui.mybatisplus.domain.UnrealizedPnl;
import com.wangfugui.mybatisplus.service.TransactionDetailService;
import com.wangfugui.mybatisplus.service.UnrealizedPnlService;
import com.wangfugui.mybatisplus.utils.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.omg.IOP.TransactionService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service
@Slf4j
public class TransactionDetailServiceImpl extends ServiceImpl<TransactionDetailDao, TransactionDetail> implements TransactionDetailService {

    @Override
    public List<TransactionDetail> list(String stockCode, Date reportDate) {
        LambdaQueryWrapper<TransactionDetail> wrapper = new LambdaQueryWrapper<>();
        wrapper.le(TransactionDetail::getDate, reportDate)
                .eq(TransactionDetail::getStockCode, stockCode)
                .eq(TransactionDetail::getOperation, "B")
                .eq(TransactionDetail::getCalculate, 0);
        return list(wrapper);
    }

    @Override
    public void tagCalculate(String stockCode, Date reportDate) {
        LambdaUpdateWrapper<TransactionDetail> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(TransactionDetail::getStockCode, stockCode)
                .eq(TransactionDetail::getDate, reportDate)
                .set(TransactionDetail::getCalculate, 1);
        update(wrapper);
    }

    @Override
    public void tagCalculate(List<Integer> ids) {
        if(ids == null || ids.size() == 0){
            return;
        }
        LambdaUpdateWrapper<TransactionDetail> wrapper = new LambdaUpdateWrapper<>();
        wrapper.in(TransactionDetail::getId, ids)
                .set(TransactionDetail::getCalculate, 1);
        update(wrapper);
    }
}
